export const sqlFragment = {
  user: `JSON_OBJECT('id', user.id, 'name', user.name,  'avatar', IF(COUNT(avatar.id), 1, null)) as user `,
  leftJoinUser: `LEFT JOIN user ON user.id = post.user_id  LEFT JOIN avatar ON avatar.user_id = user.id`,
  totalComments: `(SELECT COUNT(comment.id) FROM comment WHERE comment.post_id = post.id) as total_comments`,
  leftJoinOneFile: `LEFT JOIN LATERAL ( SELECT * FROM file WHERE file.post_id = post.id  ORDER BY file.id DESC LIMIT 1 ) AS file ON post.id = file.post_id`,
  file: `CAST(IF(COUNT(file.id), GROUP_CONCAT(DISTINCT JSON_OBJECT('id', file.id, 'width', file.width, 'height', file.height)), NULL) AS JSON ) AS file`,
  leftJoinTag: `LEFT JOIN post_tag ON post_tag.post_id = post.id LEFT JOIN tag ON tag.id = post_tag.tag_id`,
  tags: `CAST(IF(COUNT(tag.id),CONCAT('[', GROUP_CONCAT(DISTINCT JSON_OBJECT('id', tag.id, 'name', tag.name)) ,']') ,NULL) AS JSON) AS tag`,
  totalLikes: `(SELECT COUNT(user_like_post.id) FROM user_like_post WHERE user_like_post.post_id = post.id) as total_likes`,
  innerJoinUserLikePost: `INNER JOIN user_like_post ON user_like_post.post_id = post.id`
}
